package com.yang.beanfactorypostprocessor;

import com.yang.dao.Y;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @Description: 对快注入spring容器的bean进行修改
 * @Author: Yang Qiang
 * @Data: 2021/10/19
 */
// 让spring认识
@Component
public class YangBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

		// 获取我们的X类对应的BeanDefinition对象
		AbstractBeanDefinition x = (AbstractBeanDefinition)beanFactory.getBeanDefinition("x");

		// 对得到的X类对应的BeanDefinition对象进行修改
		x.setBeanClass(Y.class);
	}
}